package com.googlecode.compliancechecker;

import java.util.ArrayList;
import java.util.List;

import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureVisitor;

/**
 * Utility class to extract all type references from a signature.
 * 
 * @author Marc-Christian Schulze
 * 
 */
public class SignatureTypeExtractor implements SignatureVisitor {

	private SignatureReader		reader;
	private List<TypeReference>	references;

	public SignatureTypeExtractor(String signature) {
		references = new ArrayList<TypeReference>();
		reader = new SignatureReader(signature);
		reader.accept(this);
	}

	public List<TypeReference> getTypesOfSignature() {
		return references;
	}

	public void visitFormalTypeParameter(String name) {
		if (name == null) {
			return;
		}
		references.add(new TypeReference(0, name));
	}

	public void visitTypeVariable(String name) {
		if (name == null) {
			return;
		}
		references.add(new TypeReference(0, name));
	}

	public void visitClassType(String name) {
		if (name == null) {
			return;
		}
		references.add(new TypeReference(0, name));
	}

	public void visitInnerClassType(String name) {
		if (name == null) {
			return;
		}
		references.add(new TypeReference(0, name));
	}

	public SignatureVisitor visitClassBound() {
		return this;
	}

	public SignatureVisitor visitInterfaceBound() {
		return this;
	}

	public SignatureVisitor visitSuperclass() {
		return this;
	}

	public SignatureVisitor visitInterface() {
		return this;
	}

	public SignatureVisitor visitParameterType() {
		return this;
	}

	public SignatureVisitor visitReturnType() {
		return this;
	}

	public SignatureVisitor visitExceptionType() {
		return this;
	}

	public void visitBaseType(char descriptor) {
	}

	public SignatureVisitor visitArrayType() {
		return this;
	}

	public void visitTypeArgument() {
	}

	public SignatureVisitor visitTypeArgument(char wildcard) {
		return this;
	}

	public void visitEnd() {
	}
}
